package com.bkgy.modular.yieldReport.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.bkgy.modular.yieldReport.entity.Clickcurve;
import com.bkgy.modular.yieldReport.entity.TB_click_analysis;
import com.bkgy.modular.yieldReport.mapper.Click_analysisMapper;
import com.bkgy.modular.yieldReport.service.Click_analysisService;
import com.bkgy.sys.common.entity.ResultData;

import javax.annotation.Resource;
import java.util.List;

public class Click_analysisServiceImpl  implements Click_analysisService  {
    @Resource
    private  Click_analysisMapper click_analysisMapper;


    @Override
    public void insert_click_analysis(JSONObject jsonObject) {
        click_analysisMapper.insert_click_analysis(jsonObject);
    }

    @Override
    public ResultData get_clickcount(JSONObject jsonObject) {
        try {
            JSONObject condition = jsonObject.getJSONObject("condition");
            JSONObject json = new JSONObject();
            // 添加键值对到 JSONObject 中

            String TB_START = condition.getString("START_TIME") + " 00:00:00";
            String TB_END = condition.getString("END_TIME") + " 23:59:59";

            json.put("TB_START", TB_START);
            json.put("TB_END", TB_END);
            List<Clickcurve> cpount = click_analysisMapper.get_clickcount(condition);

            return ResultData.ResultDataSuccess(cpount);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    @Override
    public ResultData get_click_detail(JSONObject jsonObject) {
        try {
            JSONObject condition = jsonObject.getJSONObject("condition");
            List<TB_click_analysis> cpount = click_analysisMapper.get_click_detail(condition);
            return ResultData.ResultDataSuccess(cpount);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }

    @Override
    public ResultData get_clicktop30(JSONObject jsonObject) {
        try {
            JSONObject condition = jsonObject.getJSONObject("condition");
            List<TB_click_analysis> cpount = click_analysisMapper.get_clicktop30(condition);
            return ResultData.ResultDataSuccess(cpount);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }
}